package com.leyou.gateway.config;

import com.leyou.auth.utils.JwtUtils;
import com.leyou.auth.utils.RsaUtils;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.io.File;
import java.security.PublicKey;

/**
 * @author 岩冰
 * @version 1.0
 * @date:2018/10/18
 */
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties  {

    private String pubKeyPath;// 公钥

    private PublicKey publicKey; // 公钥

    private String cookieName;

    private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);
    @PostConstruct
    public void init() {
        try {
           this.publicKey= RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("查询公钥失败",e);
        }

    }

    public String getPubKeyPath() {
        return pubKeyPath;
    }

    public JwtProperties setPubKeyPath(String pubKeyPath) {
        this.pubKeyPath = pubKeyPath;
        return this;
    }

    public PublicKey getPublicKey() {
        return publicKey;
    }

    public JwtProperties setPublicKey(PublicKey publicKey) {
        this.publicKey = publicKey;
        return this;
    }

    public String getCookieName() {
        return cookieName;
    }

    public JwtProperties setCookieName(String cookieName) {
        this.cookieName = cookieName;
        return this;
    }
}
